Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nexus fix: OwnableValidator & OwnableExecutor integration + tests, + add missing features after viem refactor + fix issues & conflicts +++ #576

Merged
merged 18 commits into from
Sep 23, 2024

Conversation

VGabriel45
Copy link
Collaborator

@VGabriel45 VGabriel45 commented Sep 17, 2024

PR-Codex overview

This PR focuses on refactoring the handling of signer instead of holder in various modules and updates the related tests. It also introduces new functionalities and makes structural adjustments to improve the codebase.

Detailed summary

  • Replaced holder with signer in multiple files.
  • Updated toHolder utility to toSigner.
  • Modified function signatures and types to use Signer.
  • Added new module getPreviousModule for retrieving previous module addresses.
  • Enhanced tests for OwnableExecutor and OwnableValidator.
  • Adjusted module installation and uninstalling logic.
  • Updated the package.json dependencies.
  • Changed addresses in addresses.ts.

The following files were skipped due to too many changes: src/sdk/modules/validators/ownableValidator.test.ts, src/sdk/modules/validators/OwnableValidator.ts

✨ Ask PR-Codex anything about this PR by commenting with /codex {your question}

@livingrockrises
Copy link
Contributor

conflicts need to be resolved.

import type { Module } from "../utils/Types.js"

export class OwnableValidator extends BaseValidationModule {
public smartAccount: NexusSmartAccount
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it useful for all modules' instances to get SA instance passed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, since we are building user operations for module transactions

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, my only concern was regarding applying defaultValidatorModule when first time SA instance is created and module will expect SA instance passed.

parseAbiParameters("uint256 threshold, address[] owners"),
moduleConfig.data
)
super(moduleConfig, smartAccount.getSmartAccountOwner())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't super supposed to accept a signer?

private constructor(moduleConfig: Module, signer: SmartAccountSigner) {
    super(moduleConfig, signer)
  }

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's what smartAccount.getSmartAccountOwner() is passing

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok I thought by name it returns an address and not signer object.

public threshold: number

private constructor(
moduleConfig: Module,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Module has become a multi-purpose type. have some questions around it, as data can be interpreted multiple ways when it comes to installations and uninstallation if I'm not wrong?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You propose to create specific types for each module ? Like instead of having "Module" we would have "OwnableValidatorModuleConfig" ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is fine for now if only common properties are mandatory

smartAccount: NexusSmartAccount,
owners: Address[],
threshold?: number,
hook?: Address
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder what is the purpose of this. have noticed in module-sdk as well where a hook is always tied to any kind of a module..

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is for Kernel modules, Kernel has a hook that is associated with every validator, executor and fallback

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see

hook?: Address
): Promise<OwnableValidator> {
if (
!owners.includes(await smartAccount.getSmartAccountOwner().getAddress())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we're assuming here already initialised smart account. MUST be initialised with K1 as default

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but what if I had passed defaultValidationModule as PasskeyValidator instance in the future? generally how does smartAccount.getSmartAccountOwner() give you answer and fit with .getAddress() later.
just food for thought

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't get this, need more context

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

specific to nexus account. if default validator module is different then this would not have expected result

if (
!owners.includes(await smartAccount.getSmartAccountOwner().getAddress())
) {
throw Error("Signer needs to be one of the owners")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you mean one of the owners should also be an onwer through K1 validator module assumed to be installed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, my initial thought was that we need the smart account owner eoa to be part of this owners array too but it does not, I did some changes to fix this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup. could be totally unrelated owners

data: calldata,
value: 0n
}
const userOp = await this.smartAccount.buildUserOp([transaction]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see benefit of passing smartAccount instance is userop can be sent right away. in stead of just requesting for calldata

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exactly, we add a new layer of utility to the module instance.

Copy link
Contributor

@livingrockrises livingrockrises left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

review i

@livingrockrises
Copy link
Contributor

conflicts to be resolved

Copy link

github-actions bot commented Sep 19, 2024

size-limit report 📦

Path Size
core (esm) 11.27 KB (+1.46% 🔺)
core (cjs) 17.34 KB (+1.16% 🔺)
bundler (tree-shaking) 197 B (0%)
paymaster (tree-shaking) 108 B (0%)

@livingrockrises
Copy link
Contributor

ok new conflicts here

Copy link
Collaborator

@joepegler joepegler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great to have install functionality back. Thanks for bringing it back 💪

src/sdk/account/toNexusAccount.test.ts Outdated Show resolved Hide resolved
src/sdk/account/toNexusAccount.ts Outdated Show resolved Hide resolved
src/sdk/account/toNexusAccount.ts Outdated Show resolved Hide resolved
src/sdk/account/toNexusAccount.ts Outdated Show resolved Hide resolved
src/sdk/account/toNexusAccount.ts Outdated Show resolved Hide resolved
src/sdk/modules/validators/ownableValidator.test.ts Outdated Show resolved Hide resolved
src/sdk/modules/validators/ownableValidator.test.ts Outdated Show resolved Hide resolved
src/test/callDatas.js.map Outdated Show resolved Hide resolved
src/test/testUtils.ts Outdated Show resolved Hide resolved
src/test/testUtils.ts Outdated Show resolved Hide resolved
@joepegler
Copy link
Collaborator

Just a wider point on our modules. I don't like the folder structure any more. It's difficult to know where to look or why the folders are arranged in the way that they are. I also don't like the Base class stuff that we have now. It feels dated, and I'm not sure it even makes sense given how much variety we will have from our modules. I prefer rhinestone flatter / simplified way of organising modules. Can we replicate something similar to what they have done, paired with decorators that can be extended by a nexusClient instead? I realise this might require a different PR

@joepegler
Copy link
Collaborator

joepegler commented Sep 20, 2024

I've not given this more that a moments thought, but something like...

image

to

modules >
  smartSessions >
    abi
    constants
    installation
    index
    usage
    decorators
  ownables > 
    abi
    constants
    installation
    index
    usage
    decorators

@livingrockrises
Copy link
Contributor

checks are failing.

@livingrockrises
Copy link
Contributor

I've not given this more that a moments thought, but something like...

image `to`
modules >
  smartSessions >
    abi
    constants
    installation
    index
    usage
    decorators
  ownables > 
    abi
    constants
    installation
    index
    usage
    decorators

folder for each module is ok. most of them will be validators though for which we precisely need these classes because of default and active validator concept.

@VGabriel45
Copy link
Collaborator Author

getActiveValidationModule

We don't need this, instead we will be migrating to use rhinestone's sdk for module.

@VGabriel45 VGabriel45 changed the title Nexus fix: Ownable Validator module implementation + tests Nexus fix: OwnableValidator & OwnableExecutor integration + tests, + add missing features after viem refactor + fix issues & conflicts +++ Sep 23, 2024
const defaultedActiveModule =
activeModule ??
let defaultedActiveModule =
activeValidationModule ??
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can also call this activeValidator
but can keep this as note for now and still merge PR.

Copy link
Contributor

@livingrockrises livingrockrises left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

leaving approved

@livingrockrises livingrockrises merged commit 4ad18e4 into feat/nexus Sep 23, 2024
3 checks passed
@joepegler joepegler deleted the nexus_fix/ownableValidator branch September 23, 2024 20:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants